#include <iostream>
#include <vector>
#include <algorithm>
#include <memory.h>
using namespace std;

vector<int> G[1005];
int x, y;
int dfn[1005], low[1005];
int sum, root, n;
bool iscut[1005];

void tarjan(int x) {
	int flag = 0;
	dfn[x] = low[x] = ++sum;
	for (unsigned i = 0; i < G[x].size(); ++i) {
		int y = G[x][i];
		if (!dfn[y]) {
			tarjan(y);
			low[x] = min(low[y], low[x]);
			if (low[y] >= dfn[x]) {
				++flag;
				if (x != root || flag > 1) iscut[x] = 1;
			}
		} else {
			low[x] = min(low[x], dfn[y]);
		}
	}
}

void dfs(int x) {
	if (dfn[x]) return;
	dfn[x] = 1;
	for (unsigned i = 0; i < G[x].size(); ++i) {
		if (G[x][i] == root) continue;
		dfs(G[x][i]);
	}
}

int main() {
	int fid = 0;
	while (1) {
		n = 0;
		while (1) {
			cin >> x;
			if (x == 0) break;
			cin >> y;
			G[x].push_back(y);
			G[y].push_back(x);
			n = max(n, max(x, y));
		}
		if (n == 0) break;
		memset(dfn, 0, sizeof(dfn));
		memset(low, 0, sizeof(low));
		memset(iscut, 0, sizeof(iscut));
		
		for ( int i = 1; i <= n; ++i) {
			if (!dfn[i]) {
				root = i;
				tarjan(i);
			}
		}
		
		bool f = 1;
		cout << "Network #" << ++fid << endl;
		for (int i = 1; i <= n; ++i) {
			if (iscut[i]) {
				f = 0;
				memset(dfn, 0, sizeof(dfn));
				root = i;
				int res = 0;
				for (int j = 1; j <= n; ++j) {
					if (j == root) continue;
					if (!dfn[j]) {
						++res;
						dfs(j);
					}
				}
				cout << "  SPF node " << i << " leaves " << res << " subnets" << endl;
			}
		}
		if (f) cout << "  No SPF nodes" << endl;
		cout << endl;
		
		for (int i = 0; i <= n; ++i) {
			G[i].clear();
		}
	}
	return 0;
}
